package com.zcy.thymeleaf.controller;

import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * Created by sue on 2019/3/22.
 */
@Controller
@Log4j2
public class UploadFileController {

    @RequestMapping("/uploadShow")
    public String uploadDiv(){
        return "upload";
    }

    @RequestMapping("/upload")
    public void upload(@RequestParam MultipartFile[] myfile){

        try {
            int len = myfile.length;
            for (int i = 0; i < len; i++) {
                MultipartFile file = myfile[i];
                if (file.isEmpty()) {
                    // TODO文件为空时处理
                    return;
                } else {
                    file.transferTo(new File("d:\\" + file.getOriginalFilename()));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return;

    }

}
